package xyf.p10.dp;

/**
 * ClassName: P0518_CoinChange2
 * Description:
 * Author: xyf
 * Date: 9/9/22 10:25 AM
 * Version: 1.0
 **/
public class P0518_CoinChange2
{
    public int change(int amount, int[] coins)
    {
        int[][] dp = new int[coins.length][amount + 1];

        for (int i = 0; i * coins[0] < amount + 1; i++)
        {
            dp[0][i * coins[0]] = 1;
        }

        for (int i = 1; i < coins.length; i++)
        {
            for (int j = 0; j < amount + 1; j++)
            {
                int cnt = j / coins[i];
                for (int k = 0; k <= cnt; k++)
                {
                    dp[i][j] += dp[i - 1][j - k * coins[i]];
                }
            }
        }
        return dp[coins.length - 1][amount];
    }
}